<?php
/**
 * Created by PhpStorm.
 * User: hemenglu
 * Date: 2018/9/21
 * Time: 下午1:44
 */

namespace App\Model\Traits;


use App\Model\Comment;
use App\Model\Favorite;
use App\Model\Zan;
use App\User;

trait Common
{
    protected function user(){
        return $this->belongsTo(User::class);
    }

    public function zan(){
        return $this->morphMany(Zan::class,'zan');
    }

    public function isZan(User $user){
        return $this->zan()->where('user_id',$user['id'])->first();
    }


    public function comment(){
        return $this->morphMany(Comment::class,'comment');
    }

    public function favorite(){
        return $this->morphMany(Favorite::class,'favorite');
    }

    public function isFavorite(User $user){
        return $this->favorite()->where('user_id',$user['id'])->first();
    }

}